﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Caliburn.Micro;
using FuelTracker.Services;
using FuelTracker.Models;
using FuelTracker.Resources;

namespace FuelTracker.ViewModels
{
    [SurviveTombstone]
    public class CreateVehicleViewModel : PropertyChangedBase
    {
        private readonly INavigationService navigationService;
        private readonly IStorageService storageService;
        private readonly ParameterService parameterService;

        private string vehicleName;

        [SurviveTombstone]
        public string VehicleName
        {
            get
            {
                return vehicleName;
            }
            set
            {
                if (value != vehicleName)
                {
                    vehicleName = value;
                    NotifyOfPropertyChange(() => VehicleName);
                    NotifyOfPropertyChange(() => CanSave);
                }
            }
        }

        public bool CanSave
        {
            get { return !String.IsNullOrEmpty(vehicleName) && vehicleName.Trim() != String.Empty; }
        }

        #region Localization
        public string LabelApplicationTitleCaps
        {
            get { return Texts.Lbl_ApplicationTitleAllCaps; }
        }

        public string LabelNewVehicle
        {
            get { return Texts.Lbl_NewVehicle; }
        }

        public string LabelName
        {
            get { return Texts.Lbl_Name; }
        }

        public string LabelCancel
        {
            get { return Texts.Lbl_Cancel; }
        }

        public string LabelSave
        {
            get { return Texts.Lbl_Save; }
        }

        #endregion

        public CreateVehicleViewModel(IStorageService storageService, INavigationService navigationService, ParameterService parameterService)
        {
            this.storageService = storageService;
            this.navigationService = navigationService;
            this.parameterService = parameterService;
        }

        public void Save()
        {   
            if (CanSave)
            {
                Vehicle vehicle = new Vehicle(vehicleName.Trim());
                storageService.AddVehicle(vehicle);

                //parameterService.Push(vehicle);
                navigationService.GoBack();
            }
        }
    }
}
